package com.admin.controller;


import com.admin.entity.Admin;
import com.admin.service.IRechargeService;
import com.admin.service.impl.AdminServiceImpl;
import com.admin.service.impl.RechargeServiceImpl;
import com.bean.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author marisheng
 * @since 2019-11-21
 */
@RestController
@RequestMapping("/admin/recharge")
public class RechargeController {

    @Autowired
    private RechargeServiceImpl rechargeService;
    @Autowired
    private IRechargeService iRechargeService;
    @Autowired
    private AdminServiceImpl adminServiceImpl;

    /**
     * 沃币充值记录
     *
     * @return
     */
    @RequestMapping("/selectRechargeRecord")
    public ResponseBean MoneyRechargeRecord(@RequestParam Map<String, String> map) {
        List<Map> list = rechargeService.MoneyRechargeRecord(map);
        return new ResponseBean(200, "成功", list);
    }

    /**
     * 充值业务
     *
     * @param admin_id1    被冲值用户
     * @param admin_money1 沃币数
     * @return
     */

    @RequestMapping("/transfer")
    public ResponseBean transfer(Integer admin_id1, Integer admin_money1 , Integer admin_id) {
        Admin money = rechargeService.allMoney(admin_id);
        if ( money.getAdminMoney()< admin_money1) {
            return new ResponseBean(500, "您的沃币不足，请及时充值", null);
        } else {
            boolean f = iRechargeService.jia_jian(admin_id1, admin_money1, admin_id);
            int n = iRechargeService.inseradmin_recharge(admin_money1,  money.getAdminMoney());
            if (f && n > 0) {
                return new ResponseBean(200, "充值成功", null);
            } else {
                return new ResponseBean(500, "充值失败", null);
            }
        }
    }


}
